$("#results").flexigrid({
	height:400,
	buttons:[{
		name:'轉EXCEL',
		bclass:'edit',
		onpress:convert_excel_js
	}],
	useRp:true,
	rp:20,
	rpOptions:[20,25],
	showTableToggleBtn : true
});

function convert_excel_php(){
	window.open("convert_excel_action?operator=2","newwindow","height=180,width=400,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=no");
}

function convert_excel_js()
{ 
   var curTbl = document.getElementById("results"); 
   var oXL;
   try{
	   oXL = new ActiveXObject("Excel.Application");
   }catch(e){
	   convert_excel_php();
	   return;
   }
   
   var oWB = oXL.Workbooks.Add(); 
  
   var oSheet = oWB.ActiveSheet;
   
   var sel = document.body.createTextRange();
   sel.moveToElementText(curTbl);
   sel.select();
   sel.execCommand("Copy");
   
   oSheet.Range("A2:K5").PasteSpecial();
   
   var h_length=header.length;
   var j=1;
   for(i=0;i<h_length;i++){
	   oSheet.Cells(1,j).value=header[i];
	   j++;
   }
   
   var j=1;
   for(i=0;i<h_length;i++){
	   oSheet.Cells(1,j).Interior.ColorIndex=37;
	   oSheet.Cells(1,j).Font.Bold=true;
	   j++;
   }
   
   oXL.Visible = true;
}